package processes.printSumNProcess;

import os.MiniOS;
import os.MiniProcess;
import os.MiniThread;

public class PrintSumNProcessThread extends MiniThread
{

	private Integer N;

	public PrintSumNProcessThread(MiniProcess process, String tid)
	{
		super(process, tid);
		description = "Main Thread";
	}

	@Override
	public void run()
	{
		isExcecutionStopped();
		System.out.println("Inside Run");
		double sum = 0;
		for (int i = 0; i <= N; i++)
		{
			isExcecutionStopped();
			sum += i;
			if (i % 1000 == 0)
				System.out.println(i);
			isExcecutionStopped();
		}
		MiniOS.getInstance().outputRequest(this, "Sum = " + sum);
		isExcecutionStopped();
		System.out.println("Sum = " + sum);
		MiniOS.getInstance().threadTerminated(process.getPid(), tid);
	}

	@Override
	public void passThreadArguments(Object[] arguments)
	{
		N = (Integer) arguments[0];
	}

}
